package com.bu.model;

import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * @author xueqiang.mi
 * @since 2011-2-21
 */
@PersistenceCapable(table = "Topics", identityType = IdentityType.APPLICATION)
public class Topic {
	@PrimaryKey
	private String name;
	@Persistent
	private int level = 0;
	@Persistent
	private Set<String> children;
	@Persistent
	private Set<Long> problems;
	@Persistent
	private Date crtDate;

	public Topic() {
	}

	public Topic(String name, int level) {
		this.name = name;
		this.level = level;
	}

	public Set<String> getChildren() {
		if (children == null) {
			children = new TreeSet<String>(new Comparator<String>() {
				@Override
				public int compare(String o1, String o2) {
					return o1.compareTo(o2);
				}
			});
		}
		return children;
	}

	public Date getCrtDate() {
		return crtDate;
	}

	public int getLevel() {
		return level;
	}

	public String getName() {
		return name;
	}

	public Set<Long> getProblems() {
		if (problems == null) {
			problems = new HashSet<Long>();
		}
		return problems;
	}

	public void setChildren(Set<String> children) {
		this.children = children;
	}

	public void setCrtDate(Date crtDate) {
		this.crtDate = crtDate;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setProblems(Set<Long> problems) {
		this.problems = problems;
	}

	@Override
	public String toString() {
		return "Topic [name=" + name + ", level=" + level + ", children=" + children + ", crtDate=" + crtDate + ", problems=" + problems + "]";
	}
}
